package com.qeng.aiwanba.activity;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.LinearLayout;

import com.qeng.aiwanba.R;
import com.qeng.aiwanba.fragment.BaseFragment;
import com.qeng.aiwanba.util.ActivityManagerUtil;
import com.qeng.aiwanba.util.Constants;
import com.qeng.aiwanba.util.Util;

/**
 * Created by lixy on 2017/9/22.
 */

public class SubActivity extends BaseActivity {

    private FragmentManager fm;
    private FragmentTransaction transaction;

    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_sub);

        Util.setStateShadow(this,(LinearLayout) findViewById(R.id.staus_ll));

        ActivityManagerUtil.popActivity(getLocalClassName(),this);

        url = getIntent().getStringExtra("url");

        fm = getFragmentManager();
        transaction = fm.beginTransaction();
        BaseFragment fragment = BaseFragment.newInstance(url);
        transaction.add(R.id.sub_container, fragment);
        Constants.topFrgment = fragment;

        transaction.commit();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Constants.topFrgment.noticeJsKeyBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onDestroy() {
        ActivityManagerUtil.pushActivity(getLocalClassName());
        super.onDestroy();
    }
}
